package org.pi.common.gui.helper

/** Trait to hide and handle evil gui magic, in this case 
* mouse interactions (clicks and drags).
*/
trait MouseInteractions {
	/** other connected MouseInteractions */ 
	private val others = scala.collection.mutable.Set[MouseInteractions]()
	/** helper variable to inhibit endless recursion */ 
	private var onGoingNotification : Boolean = false
	/** the user clicked somewhere */
	def selectPoint(x: Int, y:Int, button: Int) : Unit = {
		if (onGoingNotification==false) {
			onGoingNotification = true;
			others.foreach( _.selectPoint(x,y,button) );
			onGoingNotification = false;
		}
	}
	/** the use selected a region (mouse-drag) */
	def selectRegion(x1:Int, y1:Int, x2:Int, y2:Int) : Unit = {
		if (onGoingNotification==false) {
			onGoingNotification = true;
			others.foreach( _.selectRegion(x1,y1,x2,y2) );
			onGoingNotification = false;
		}
	}
	/** the user clicked somewhere */
	def callMenu(x: Int, y:Int) : Unit = {
		if (onGoingNotification==false) {
			onGoingNotification = true;
			others.foreach( _.callMenu(x,y) );
			onGoingNotification = false;
		}
	}
	/** clone Mouse */
	def sendAllMouseInteractionsTo(destination: MouseInteractions) : Unit = {
		others += destination
	}
}
